var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/cmd/use-lint.ts
var use_lint_exports = {};
__export(use_lint_exports, {
  default: () => use_lint_default
});
module.exports = __toCommonJS(use_lint_exports);
var utils = __toESM(require("@umijs/utils"));
var import_fs = require("fs");
var import_path = require("path");
var execa2 = (command, args, cwd) => {
  return utils.execa(command, args, {
    env: {
      FORCE_COLOR: true
    },
    cwd
  });
};
var use_lint_default = (api) => {
  api.registerCommand({
    name: "use-lint",
    description: "generate eslint, stylelint, prettier config file",
    details: `
$ umi use-lint
    `,
    async fn() {
      const tplsPath = (0, import_path.join)(__dirname, "../../templates");
      const files = utils.glob.sync(".*", {
        cwd: tplsPath
      });
      const cwd = api.paths.cwd;
      utils.mkdirp.sync(cwd);
      files.forEach((file) => {
        const source = (0, import_path.join)(tplsPath, file);
        const target = (0, import_path.join)(cwd, file);
        (0, import_fs.copyFileSync)(source, target);
      });
      const pkg = api.pkg;
      pkg.scripts = {
        ...pkg.scripts,
        "lint:es": "umi eslint",
        "lint:style": "umi stylelint",
        "lint:prettier": "umi prettier",
        lint: "umi szlint",
        prettier: "umi write"
      };
      const pkgPath = (0, import_path.join)(cwd, "package.json");
      (0, import_fs.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2));
      await execa2("npx", ["husky", "install"], cwd);
      const preCommitPath = (0, import_path.join)(cwd, ".husky/pre-commit");
      let preCommitFile = "";
      try {
        preCommitFile = (0, import_fs.readFileSync)(preCommitPath, { encoding: "utf-8" });
      } catch (err) {
        await execa2("npx", ["husky", "add", ".husky/pre-commit", "npx umi lint-staged"], cwd);
      }
      if (preCommitFile.indexOf("npx umi lint-staged") === -1) {
        await execa2("npx", ["husky", "add", ".husky/pre-commit", "npx umi lint-staged"], cwd);
      }
      const commitMsgPath = (0, import_path.join)(cwd, ".husky/commit-msg");
      let commitMsgFile = "";
      try {
        commitMsgFile = (0, import_fs.readFileSync)(commitMsgPath, { encoding: "utf-8" });
      } catch (err) {
        await execa2("npx", ["husky", "add", ".husky/commit-msg", "npx --no-install umi commitlint"], cwd);
      }
      if (commitMsgFile.indexOf("npx --no-install umi commitlint") === -1) {
        await execa2("npx", ["husky", "add", ".husky/commit-msg", "npx --no-install umi commitlint"], cwd);
      }
    }
  });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
